
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> 微达 </title>

<meta name="description" content="微达如此牛逼云云">
<meta name="keywords" content="微博,达到">
<meta name="title" content="微达 - 物联网的开端">
<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet">
</head>
<body>  

<div class="container">
<!--
<div class="alert">
</div>
-->

<div class="well">
<legend>
使用电子邮箱注册微达的新帐号
</legend>

<form class="form-horizontal" id="register" action="/register" method="post">
<div class="control-group" id="register_email">
<label class="control-label">邮箱地址</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-envelope"></i></span>
<input ref_method="register_validate_email" type="text" name="email" autocomplete="off" value="">
</div>
<span class="help-inline"></span>
</div>
</div>
<div class="control-group" id="register_nickname">
<label class="control-label">昵称</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-user"></i></span>
<input ref_method="register_validate_nickname" type="text" autocomplete="off" name="nickname" value="">
</div>
<span class="help-inline"></span>
</div>
</div>
<div class="control-group" id="register_pwd">
<label class="control-label">密码</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-asterisk"></i></span>
<input type="password" ref_method="register_validate_pwd" autocomplete="off" name="password" value="">
</div>
<span class="help-inline"></span>
</div>
</div>
<div class="control-group">
<label class="control-label">确认密码</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-asterisk"></i></span>
<input type="password" name="re_password" autocomplete="off" ref_method="register_validate_repassword" value="">
</div>
<span class="help-inline"></span>
</div>
</div>
<div class="control-group">
<div class="controls">
<button class="btn btn-primary" type="submit">注册新帐号</button>
</div>
</div>
</form>
</div>


</div>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script src="http://twitter.github.com/bootstrap/assets/js/bootstrap.min.js"></script>
<script>
$(function() {
    $('#register input').blur(function(event) {
        var target = $(event.target);
        var $group = target.parents('div .control-group');
        var $help = target.parents('.controls').children('.help-inline');

        var method = target.attr("ref_method");
        var value = target.val();
        $group.removeClass('error');
        $group.removeClass('success');
        $help.text('');

        if ( value == "" ) {
            $group.addClass('error');
            $help.text('不能为空。');
            return false;
        }

        if ( method == "register_validate_repassword" ) {
            var pwd = $('#register #register_pwd input').attr('value');
            if ( value != pwd ) {
                $group.addClass('error');
                $help.text('两次输入的密码不一致。');
                return false;
            }
            else {
                return true;
            }
        }

        var url = [
            '/reflect/',
            method,
            '/e30=/',
            encodeURIComponent(value)
        ];
        url = url.join('');

        $.getJSON( url, function(data) {
            if ( 1 == data['code'] ) {
                $group.addClass('success');
                $help.text('OK!');
            }else if ( 0 == data['code'] ) {
                $group.addClass('error');
                $help.text(data.err_msg);
            }
        });

    });

    $('#register').submit(function(){
        $error = $('#register .error');
        var success = $('#register .success');
        if( $error.length > 0 || success.length < 1 ){
            alert('您输入的内容不正确，请检查后提交。');
            return false;
        }
        return true;
    });

});



</script>


</body>
</html>
